<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <!-- 头部区域 -->
    <ul class="layui-nav layui-layout-left">
      <li class="layui-nav-item layadmin-flexible" lay-unselect>
        <a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">
          <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
        </a>
      </li>
      <!--<li class="layui-nav-item layui-this layui-hide-xs layui-hide-sm layui-show-md-inline-block">
        <a lay-href="" title="">
          控制台
        </a>
      </li>-->
<!--      <li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a href="http://www.layui.com/admin/" target="_blank" title="前台">
          <i class="layui-icon layui-icon-website"></i>
        </a>
      </li>-->
      <li class="layui-nav-item" lay-unselect>
        <a href="javascript:;" layadmin-event="refresh" title="刷新">
          <i class="layui-icon layui-icon-refresh-3"></i>
        </a>
      </li>
    </ul>
    <ul class="layui-nav layui-layout-right" lay-filter="layadmin-layout-right">
      
      <li class="layui-nav-item" lay-unselect>
        <a lay-href="app/message/" layadmin-event="message">
          <i class="layui-icon layui-icon-notice">提醒</i>
          
          <!-- 如果有新消息，则显示小圆点 -->
          <!--../../start/layui/images/im/header.png-->
          <script type="text/html" template lay-url="../../start/json/message/new.js">
          {{# if(d.data.newmsg){ }} 
            <span class="layui-badge-dot"></span>
          {{# } }}
          </script>
          
        </a>
      </li>
      <li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a href="javascript:;" layadmin-event="theme">
          <i class="layui-icon layui-icon-theme">主题</i>
        </a>
      </li>
      <li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a href="javascript:;" layadmin-event="note">
          <i class="layui-icon layui-icon-note">便签</i>
        </a>
      </li>
      <li class="layui-nav-item" lay-unselect>
        <script type="text/html" template lay-url="/system/tsUser/ajaxSessionTsUser.do"
                lay-done="layui.element.render('nav', 'layadmin-layout-right');">
          <a href="javascript:;">
            <cite>{{ d.data.userName}}&nbsp;&nbsp;(系统管理员)</cite>
          </a>
          <dl class="layui-nav-child">
            <dd><a lay-href="set/user/info">基本资料</a></dd>
            <dd><a lay-href="set/user/password">修改密码</a></dd>
            <hr>
            <dd layadmin-event="logout" style="text-align: center;"><a>退出</a></dd>
          </dl>
        </script>
      </li>
      
      <li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a href="javascript:;" layadmin-event="about"><i class="layui-icon layui-icon-more-vertical"></i></a>
      </li>
      <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-unselect>
        <a href="javascript:;" layadmin-event="more"><i class="layui-icon layui-icon-more-vertical"></i></a>
      </li>
    </ul>
  </div>
  
  <!-- 侧边菜单 -->
  <div class="layui-side layui-side-menu">
    <div class="layui-side-scroll">
      <script type="text/html" template lay-url="/system/tsMenu/loadMenu.do"
      lay-done="layui.element.render('nav', 'layadmin-system-side-menu');" id="TPL_layout">
      
        <div class="layui-logo" lay-href="">
          <span>{{ layui.setter.name || 'layuiAdmin' }}</span>
        </div>
        
        <ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu">
        {{# 
          var path =  layui.router().path
          ,pathURL = layui.admin.correctRouter(path.join('/'))
          ,dataName = layui.setter.response.dataName;
          
          layui.each(d[dataName], function(index, item){ 
            var hasChildren = typeof item.list === 'object' && item.list.length > 0
            ,classSelected = function(){
              var match = path[0] == item.name || (index == 0 && !path[0]) 
              || (item.jump && pathURL == layui.admin.correctRouter(item.jump)) || item.spread;
              if(match){
                return hasChildren ? 'layui-nav-itemed' : 'layui-this';
              }
              return '';
            }
            ,url = (item.jump && typeof item.jump === 'string') ? item.jump : item.name;
        }}
          <li data-name="{{ item.name || '' }}" data-jump="{{ item.jump || '' }}" class="layui-nav-item {{ classSelected() }}">
            <a href="javascript:;" {{ hasChildren ? '' : 'lay-href="'+ url +'"' }} lay-tips="{{ item.title }}" lay-direction="2">
              <i class="layui-icon {{ item.icon }}"></i>
              <cite>{{ item.title }}</cite>
            </a>
            {{# if(hasChildren){ }}
              <dl class="layui-nav-child">
              {{# layui.each(item.list, function(index2, item2){ 
                var hasChildren2 = typeof item2.list == 'object' && item2.list.length > 0
                ,classSelected2 = function(){
                  var match = (path[0] == item.name && path[1] == item2.name) 
                  || (item2.jump && pathURL == layui.admin.correctRouter(item2.jump)) || item2.spread;
                  if(match){
                    return hasChildren2 ? 'layui-nav-itemed' : 'layui-this';
                  }
                  return '';
                }
                ,url2 = (item2.jump && typeof item2.jump === 'string') 
                  ? item2.jump 
                : [item.name, item2.name, ''].join('/');
              }}
                <dd  data-name="{{ item2.name || '' }}"  data-jump="{{ item2.jump || '' }}" 
                {{ classSelected2() ? ('class="'+ classSelected2() +'"') : '' }}>
                  <a href="javascript:;" {{ hasChildren2 ? '' : 'lay-href="'+ url2 +'"' }}>{{ item2.title }}</a>
                  {{# if(hasChildren2){ }}
                    <dl class="layui-nav-child">
                      {{# layui.each(item2.list, function(index3, item3){ 
                        var match = (path[0] == item.name && path[1] == item2.name && path[2] == item3.name) 
                        || (item3.jump && pathURL == layui.admin.correctRouter(item3.jump))
                        ,url3 = (item3.jump && typeof item3.jump === 'string') 
                          ? item3.jump 
                        : [item.name, item2.name, item3.name].join('/')
                      }}
                        <dd data-name="{{ item3.name || '' }}"  data-jump="{{ item3.jump || '' }}" 
                        {{ match ? 'class="layui-this"' : '' }}>
                          <a href="javascript:;" lay-href="{{ url3 }}" {{ item3.iframe ? 'lay-iframe="true"' : '' }}>{{ item3.title }}</a>
                        </dd>
                      {{# }); }}
                    </dl>
                  {{# } }}
                </dd>
            {{# }); }}
            </dl>
            {{# } }}
          </li>
        {{# }); }}
        </ul>
      </script>
    </div>
  </div>
  

  <!-- 页面标签 -->
  <script type="text/html" template lay-done="layui.element.render('nav', 'layadmin-pagetabs-nav')">
    {{# if(layui.setter.pageTabs){ }}
    <div class="layadmin-pagetabs" id="LAY_app_tabs">
      <div class="layui-icon layadmin-tabs-control layui-icon-prev" layadmin-event="leftPage"></div>
      <div class="layui-icon layadmin-tabs-control layui-icon-next" layadmin-event="rightPage"></div>
      <div class="layui-icon layadmin-tabs-control layui-icon-down">
        <ul class="layui-nav layadmin-tabs-select" lay-filter="layadmin-pagetabs-nav">
          <li class="layui-nav-item" lay-unselect>
            <a href="javascript:;"></a>
            <dl class="layui-nav-child layui-anim-fadein">
              <dd layadmin-event="closeThisTabs"><a href="javascript:;">关闭当前标签页</a></dd>
              <dd layadmin-event="closeOtherTabs"><a href="javascript:;">关闭其它标签页</a></dd>
              <dd layadmin-event="closeAllTabs"><a href="javascript:;">关闭全部标签页</a></dd>
            </dl>
          </li>
        </ul>
      </div>
      <div class="layui-tab" lay-unauto lay-allowClose="true" lay-filter="layadmin-layout-tabs">
        <ul class="layui-tab-title" id="LAY_app_tabsheader">
          <li lay-id="/"><i class="layui-icon layui-icon-home"></i></li>
        </ul>
      </div>
    </div>
    {{# } }}
  </script>
  <!-- 主体内容 -->
  <div class="layui-body" id="LAY_app_body">
    <div class="layadmin-tabsbody-item layui-show">

    </div>
    <div class="layui-footer footer">
      <div class="layui-main">
        <p>© 2018 <a href="/">cqyuanlang.com</a> 版权所有：重庆源狼软件科技有限责任公司v1.0(建议使用谷歌浏览器)</p>
        <p>
          <!--<a href="http://fly.layui.com/case/2018/" target="_blank">案例</a>
          <a href="http://fly.layui.com/jie/3147/" target="_blank">支持</a>
          <a href="javascript:;" site-event="contactInfo">联系</a>
          <a href="https://github.com/sentsin/layui/" target="_blank" rel="nofollow">GitHub</a>
          <a href="https://gitee.com/sentsin/layui" target="_blank" rel="nofollow">码云</a>
          <a href="http://fly.layui.com/jie/2461/" target="_blank">微信公众号</a>-->
        </p>
        <p class="site-union">
         <!-- <a href="https://www.upyun.com?from=layui" target="_blank" rel="nofollow" upyun=""><img src="//res.layui.com/static/images/other/upyun.png?t=1"></a>
         <span>提供 CDN 赞助</span>-->
        </p>
      </div>
    </div>
  </div>
  <!-- 辅助元素，一般用于移动设备下遮罩 -->
  <div class="layadmin-body-shade" layadmin-event="shade"></div>
</div>
<script>
  layui.use(['layim','common','view'], function(layim,common,view){
    //先来个客服模式压压精
    layim.config({
      brief: false //是否简约模式（如果true则不显示主面板）
      // 初始化获取接口
      ,init:{
        url: common.basePath+'system/im/api/init.do' //接口地址（返回的数据格式见下文）
        //,type: 'get' //默认get，一般可不填
         ,data: {access_token: layui.data('layuiAdmin').access_token} //额外参数
      }
      //查看群员接口
     ,members: {
      url: common.basePath+'system/im/api/members.do'
      ,data: {access_token: layui.data('layuiAdmin').access_token}
      }
      // 拓展工具栏
      ,tool: [{
        alias: 'code'
        ,title: '代码'
        ,icon: '&#xe64e;'
      }]
      ,title:'小秘书'
      ,skin:null
      // ,msgbox: layui.cache.dir + 'css/modules/layim/html/msgbox.html' //消息盒子页面地址，若不开启，剔除该项即可
       ,find: layui.cache.dir + 'css/modules/layim/html/find.html' //发现页面地址，若不开启，剔除该项即可
      // ,chatLog: layui.cache.dir + 'css/modules/layim/html/chatlog.html' //聊天记录页面地址，若不开启，剔除该项即可
    });
    // 监听layui.im
    var socket = new WebSocket("ws://"+common.wsPath+"socket/socket.do");
    socket.onopen = function(){
      var open = {
        "type":"onOpen",
        "data":{
         "access_token":layui.data('layuiAdmin').access_token
        }
      }
      socket.send(JSON.stringify(open));
    };

    // layim消息发送
    layim.on('sendMessage', function(res){
      console.log(JSON.stringify(res));
      //监听到上述消息后，就可以轻松地发送socket了，如：
      socket.send(JSON.stringify({
        type: 'sendMessage' // 随便定义，用于在服务端区分消息类型
        ,data: res
      }));
    });


    //监听收到的消息
    socket.onmessage = function(res){
      debugger
      // res  为接受到的值，如 {"emit": "messageName", "data": {}}
      // emit 即为发出的事件名，用于区分不同的消息
     var resContent = JSON.parse(res.data);
      if(resContent.emit === 'chatMessage'){
        layim.getMessage(resContent.data); //res.data即你发送消息传递的数据（阅读：监听发送的消息）
      }
    };
    //*** 添加好友和群组方法
  });

// 组织浏览器F5刷新操作，防止第二次进行加载小狼 ， 该段代码可以注释
/*  document.onkeydown = function(e){
    e = window.event || e;
    var keycode = e.keyCode || e.which;
    if(keycode == 116){
      if(window.event){// ie
        try{e.keyCode = 0;}catch(e){}
        e.returnValue = false;
      }else{ // firefox
        e.preventDefault();
      }
    }
  }*/
  /**
   * 解决路由跳转问题
   */
  function findRender(){
    layui.view('layui-layer-iframe2').render('/senior/im/find').then(function(){
      //视图文件请求完毕，视图内容渲染前的回调
    }).done(function(){
      //视图文件请求完毕和内容渲染完毕的回调
    });
  }

</script>